<?php

namespace App\Admin\Actions\DivinationAction;

use App\Models\YaoDivination;
use Illuminate\Support\Facades\DB;
use Encore\Admin\Actions\RowAction;
use Illuminate\Database\Eloquent\Model;
use App\Jobs\MakeDeepContentJob;
use App\Models\Category;


class MakeDeepThink extends RowAction
{
    public $name = '生成深度解析';
    
    public function handle(Model $model)
    {
	    

	    $all = YaoDivination::query()->where('divination_id',$model->id)->get();
	    $categories = Category::query()->where("is_show",1)->get();


	    foreach($all as $k=>$v){

	    	foreach($categories as $ck=>$cv){
	    		dispatch(new MakeDeepContentJob($v->divination_id,$v->by_dividend_id,$cv->id))->onQueue('deep');
	    	}


	    }

    	//dispatch(new MakeDeepContentJob($model))->onQueue('deep');


	    return $this->response()->success('正在生成中...')->refresh();

    }
	
	public function dialog()
	{
		$this->confirm('确定重新生成本挂的深度解析吗?');
	}
}
